// 常用函数
package utils

import (
	"bufio"
	"os"
	"strings"
)

// 读取文件到string切片，或者返回错误
func ReadFileStrings(fileName string) ([]string, error) {
	var lines []string
	file, err := os.Open(fileName)
	if err != nil {
		return lines, err
	}

	scanner := bufio.NewScanner(file)
	for scanner.Scan() {
		line := scanner.Text()
		line = strings.TrimSpace(line)
		lines = append(lines, line)
	}

	err = file.Close()
	if err != nil {
		return lines, err
	}

	if scanner.Err() != nil {
		return lines, scanner.Err()
	}

	return lines, nil
}
